package com.tm.d1.properties;


import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;

/**
 * 2024/6/21 读取属性文件,判断是否存在李方,存在年龄改为18 11：03
 */
public class PropertiesTest3 {
    public static void main(String[] args) throws IOException {
        //1.加载属性文件的键值对到程序中来
        Properties properties = new Properties();

        //2.开始加载
       properties.load(new FileReader("properties-app\\src\\test\\java\\user.txt"));

        //3.判断是否包含李方这个键
     if(properties.contains("李")){
         properties.setProperty("李","18");
     }

        //4.把properties对象的键值对数据从新写出去到属性文件中去
         properties.store(new FileWriter("properties-app\\src\\test\\java\\user.txt"),"success");
    }
}
